package com.health.tools;

import java.util.ArrayList;

import com.health.R;
import com.health.adapter.SearchDaAdapter;
import com.health.viewscontrols.NovaApplication;
import com.health.viewscontrols.focusgroup.ChildActivity;
import com.health.viewscontrols.focusgroup.FJHActivity;
import com.health.viewscontrols.focusgroup.GXBActivity;
import com.health.viewscontrols.focusgroup.GXYActivity;
import com.health.viewscontrols.focusgroup.JSJBctivity;
import com.health.viewscontrols.focusgroup.MaternityActivity;
import com.health.viewscontrols.focusgroup.NCZActivity;
import com.health.viewscontrols.focusgroup.OlderActivity;
import com.health.viewscontrols.focusgroup.TNBActivity;
import com.health.model.PeopleType;
import com.health.model.LabelsBean;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.widget.LabelsView;

import android.content.Context;
import android.content.Intent;
import android.text.SpannableString;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

/**
 * 设置数据
 *
 * @author nova
 */
public class PopData {

    /**
     * 一般
     */
    public static final String TAG_NORMAL = "tag_normal";
    /**
     * 二级
     */
    public static final String TAG_WARNING = "tag_warning";

    public static Context mContext = null;
    private OnClickListener onClickListener;

    public interface OnClickListener {
        void setOnClickItemListener(Object data);
    }

    public void setOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }


    /**
     * 设置疾病人群标签
     *
     * @param info
     * @author 王婷婷
     * @date 2018年1月8日 下午6:11:31
     */
    public void setPopInfo(LabelsView labelsView, final ARCHIVE_BASEINFO info, String flag, Context ctx, OnClickListener monClickListener) {
        this.onClickListener = monClickListener;
        /** 1:一般人群，2：儿童，3：孕产妇，4：老年人，5：重精神病，6：高血压，7：糖尿病，8：冠心病，9：脑卒中默认值1 */
        mContext = ctx;
        if (!TextUtils.isEmpty(info.getPOPULATION_TYPE())) {
            System.out.println("姓名："+info.getCUSTOMERNAME());
            String pop = info.getPOPULATION_TYPE();
            String[] pops = pop.split(",");
            String str_name = "";
            ArrayList<LabelsBean> testList = new ArrayList<>();

            for (String str : pops) {
                if (!TextUtils.isEmpty(str)) {
                    if (PeopleType.YBRQ.equals(str)) {
                        testList.add(new LabelsBean(PeopleType.YBRQ_NAME, PeopleType.YBRQ));
                    } else if (PeopleType.CHILD.equals(str)) {
                        testList.add(new LabelsBean(PeopleType.CHILD_NAME, PeopleType.CHILD));
                    } else if (PeopleType.WOMAN.equals(str)) {
                        testList.add(new LabelsBean(PeopleType.WOMAN_NAME, PeopleType.WOMAN));
                    } else if (PeopleType.OLD.equals(str)) {
                        testList.add(new LabelsBean(PeopleType.OLD_NAME, PeopleType.OLD));
                    } else if (PeopleType.GXY.equals(str)) {
                        testList.add(new LabelsBean(PeopleType.GXY_NAME, PeopleType.GXY));
                    } else if (PeopleType.TNB.equals(str)) {
                        testList.add(new LabelsBean(PeopleType.TNB_NAME, PeopleType.TNB));
                    } else if (PeopleType.GXB.equals(str)) {
                        testList.add(new LabelsBean(PeopleType.GXB_NAME, PeopleType.GXB));
                    } else if (PeopleType.NCZ.equals(str)) {
                        testList.add(new LabelsBean(PeopleType.NCZ_NAME, PeopleType.NCZ));
                    } else if (PeopleType.JSB.equals(str)) {
                        testList.add(new LabelsBean(PeopleType.JSB_NAME, PeopleType.JSB));
                    } else if (PeopleType.FJH.equals(str)) {
                        testList.add(new LabelsBean(PeopleType.FJH_NAME, PeopleType.FJH));
                    }
                    if (TAG_NORMAL.equals(flag)) {
                        if (PeopleType.CJR.equals(str)) {
                            testList.add(new LabelsBean(PeopleType.CJR_NAME, PeopleType.CJR));
                        }
                    }
                }
            }

            labelsView.setLabels(testList, new LabelsView.LabelTextProvider<LabelsBean>() {
                @Override
                public CharSequence getLabelText(TextView label, int position, LabelsBean data) {
                    return data.getName();
                }
            });
            labelsView.setSelectType(LabelsView.SelectType.MULTI);

            if (TAG_WARNING.equals(flag)) {
                labelsView.setMaxSelect(1);
                labelsView.setOnLabelClickListener(new LabelsView.OnLabelClickListener() {
                    @Override
                    public void onLabelClick(TextView label, Object data, int position) {
                        onClickListener.setOnClickItemListener(data);
                    }
                });
            }
        }
        labelsView.setLabelTextColor(R.color.appgreen);
    }

    /**
     * 设置人群分类背景
     *
     * @param popTypeName
     * @return
     * @author 王婷婷
     * @date 2018年1月8日 下午6:16:50
     */
    private SpannableString setPopNameType(String popTypeName) {
        SpannableString span_ybrq;
        span_ybrq = new SpannableString(popTypeName);
        // span_ybrq.setSpan(new
        // RoundBackgroundColorSpan(Color.parseColor("#FCCC7D"),
        // Color.parseColor("#FFFFFF")), 0,
        // popTypeName.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return span_ybrq;
    }

    private static int sp2px(Context context, float spValue) {
        final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
        return (int) (spValue * fontScale + 0.5f);
    }
}
